local Msg = require("core.Msg")
local LvExcel = require("excel.OperateActivity").lvRank
local Grid = require("bag.Grid")
local ActDefine = require("activity.Define")
local BagLogic = require("bag.BagLogic")
local Broadcast = require("broadcast.Broadcast")
local Lang = require("common.Lang")
local OperateActFL = require("activity.OperateActFL")
local HtmlUtil = require("common.HtmlUtil")
local ChongzhiDraw = require("activity.operate.ChongzhiDraw")
local Log = require("common.Log")
local RankHandlerL = require("rank.HandlerL")

LV_RANK_NAME = LV_RANK_NAME or {}

function open(human, id, type)
  local sendMsg = Msg.gc.GC_OPEN_YUNYING_ACTIVITY
  local activityNum
  if type == 2 then
    activityNum = OperateActFL.onGetTomorrowActRuleID(id)
  else
    activityNum = OperateActFL.onGetCurActRuleID(id)    
  end
  local activity = LvExcel[activityNum]
  if not activity then
    return
  end
  sendMsg.info[0] = #activity.condition
  local cache = {}
  for i=1, #activity.condition do
    sendMsg.info[i].reward[0] = #activity.reward[i]
    for j=1, #activity.reward[i] do
      Grid.create(cache, activity.reward[i][j][1], activity.reward[i][j][2])
      Grid.makeItem(cache, sendMsg.info[i].reward[j], 0, human)
    end
    sendMsg.info[i].args[0] = 2
    sendMsg.info[i].args[1] = activity.condition[i]
    sendMsg.info[i].args[2] = LV_RANK_NAME.sex or 0
    sendMsg.info[i].canGet = 0
    sendMsg.info[i].name = LV_RANK_NAME.name or ""
  end
  sendMsg.myInfo[0] = 1
  sendMsg.myInfo[1] = human.db.dailyChongzhi
  sendMsg.activityId = id 
  sendMsg.type = type or 1 
  Msg.send(sendMsg, human.fd)
end
--领取奖励
function getReward(human, id, index)
  if true then
    return false
  end
  
  local activityNum = OperateActFL.onGetCurActRuleID(id)
  local activity = LvExcel[activityNum]
  if not activity then
    return
  end
  if not BagLogic.checkCanAddItemList(human, activity.reward[index], #activity.reward[index]) then
    return Broadcast.sendBroadcast(human, Lang.DOWN, Lang.YUNYING_BAG_NOT_ENOUGH)
  end
  
  for i=1, #activity.reward[index] do
    BagLogic.addItem(human, activity.reward[index][i][1], 1, activity.reward[index][i][2], "yunyingAcvity")
  end
  open(human, id)
end
